<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" 
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="${entity.daoPackageName}.I${entity.className}Dao">

    <resultMap type="${entity.className}" id="${entity.classInstanceName}Map">
        <id column="${entity.idColumn}" property="${entity.idName}" />
        <#list entity.propList as prop>
        <#if prop.propName != "isDeleted">
        <result column="${prop.column}" property="${prop.propName}"/>
        </#if>
        </#list>
    </resultMap>

    <sql id="Base_Column_List">
    	${entity.idColumn},
        <#list entity.propList as prop>
        <#if prop.propName != "isDeleted">
        ${prop.column}<#if prop_has_next>, </#if>
        </#if>
        </#list>
    </sql>

	<select id="getById" parameterType="long" resultMap="${entity.classInstanceName}Map">
    	SELECT 
          <include refid="Base_Column_List" />  
        FROM ${entity.tableName}
        WHERE ${entity.idColumn}=${entity.poundSign}{${entity.idName}}
    </select>

	<select id="find" parameterType="${entity.className}" resultMap="${entity.classInstanceName}Map">
    	SELECT 
        <include refid="Base_Column_List" /> 
        FROM ${entity.tableName}
		<where>
		<if test="${entity.idName} != null and ${entity.idName} != '' ">
			AND ${entity.idColumn}=${entity.poundSign}{${entity.idName}}
		</if>
		</where>
    </select>

	 <select id="findList" parameterType="${entity.className}" resultMap="${entity.classInstanceName}Map">
        SELECT 
        <include refid="Base_Column_List" /> 
        FROM ${entity.tableName}
        WHERE is_deleted = '0'
		<if test="${entity.idName} != null and ${entity.idName} != '' ">
			AND ${entity.idColumn}=${entity.poundSign}{${entity.idName}}
		</if>
    </select>

	<select id="findAllList" resultMap="${entity.classInstanceName}Map">
    	SELECT 
        <include refid="Base_Column_List" /> 
        FROM ${entity.tableName}
    </select>
    
    <insert id="insert" parameterType="${entity.className}">
        INSERT INTO ${entity.tableName} (<#list entity.propList as prop>${prop.column}<#if prop_has_next>,</#if></#list>)
        VALUES (<#list entity.propList as prop>${entity.poundSign}{${prop.propName}}<#if prop_has_next>,</#if></#list>)
    </insert>
    
    <insert id="insertBatch" parameterType="list">
        INSERT INTO ${entity.tableName} (<#list entity.propList as prop>${prop.column}<#if prop_has_next>,</#if></#list>)
        VALUES
        <foreach collection="list" item="item" index="index" separator=","> 
		(
			<#list entity.propList as prop>${entity.poundSign}{item.${prop.propName}}<#if prop_has_next>,</#if></#list>
		)
		</foreach>
    </insert>

	<update id="updateById" parameterType="${entity.className}">
        UPDATE ${entity.tableName} SET 
        <#list entity.propList as prop>
            ${prop.column}=${entity.poundSign}{${prop.propName}}<#if prop_has_next>,</#if>
        </#list>
          WHERE ${entity.idColumn}=${entity.poundSign}{${entity.idName}}
    </update>

    <update id="update" parameterType="${entity.className}">
        UPDATE ${entity.tableName} SET 
        <#list entity.propList as prop>
            ${prop.column}=${entity.poundSign}{${prop.propName}}<#if prop_has_next>,</#if>
        </#list>
          WHERE ${entity.idColumn}=${entity.poundSign}{${entity.idName}}
    </update>
    
    <delete id="deleteById" parameterType="long">
        DELETE FROM ${entity.tableName} WHERE ${entity.idColumn}=${entity.poundSign}{${entity.idName}}
    </delete>

	<delete id="delete" parameterType="${entity.className}">
		DELETE FROM ${entity.tableName} WHERE ${entity.idColumn}=${entity.poundSign}{${entity.idName}}
	</delete>

    <delete id="deleteLogicallyById" parameterType="long">
         UPDATE ${entity.tableName} SET
            is_deleted = '1'
         WHERE ${entity.idColumn}=${entity.poundSign}{${entity.idName}}
    </delete>
	
	<delete id="deleteLogically" parameterType="${entity.className}">
		 UPDATE ${entity.tableName} SET
		 	is_deleted = '1'
		 WHERE ${entity.idColumn}=${entity.poundSign}{${entity.idName}}
	</delete>
    
</mapper>